// Planar graph colouring
// Beware: The test cases contain a false graph according to the problem statement
// So trying to find a 4-colour solution with it gives no result.
// I made a request and the judge confirmed that it was the mistake from data copied from the official website.

#include <iostream>
#include <sstream>
#include <cstdio>
#include <string.h>
#include <string>

using namespace std;

int n, numColour;
bool adj[26][26];
int colour[26];

// whether or not attempt to colour node u with colour c will lead to a correct colouring
bool attempt(int u, int c)
{
	// if there exists another node v with colour c already, this attempt is incorrect.
	for (int v = 0; v < n; v++)
		if (adj[u][v] && colour[v] == c) return false;

	// otherwise, we try it with colour c
	colour[u] = c;

	// find an adjacent not-yet-coloured node v, attempt it with all possible colours
	for (int v = 0; v < n; v++)
		if (adj[u][v] && colour[v] == 0)
		{
			int found = false;

			for (int pc = 1; pc <= numColour; pc++)
			{
				if (attempt(v, pc))
				{
					found = true;
					break;
				}
				else colour[v] = 0; 
			}
			if (!found) return false;
		}
	
	// after all, if this colouring satisfies all the adjacent nodes then we say it is correct so far.
	return true;
}

int main()
{
	while (scanf("%d\n", &n))
	{
		if (n == 0) break;
		memset(adj, false, sizeof(adj));

		for (int i = 0; i < n; i++) 
		{
			string s;
			getline(cin, s);
			stringstream ss(s);

			char repeater, c;
			string a;

			ss >> repeater >> c >> a;
			for (int j = 0; j < (int) a.size(); j++) adj[repeater-'A'][a[j]-'A'] = true;			
		}

		for (numColour = 1; numColour <= 3; numColour++)
		{
			memset(colour, 0, sizeof(colour));

			for (int i = 0; i < n; i++) 
				if (colour[i] == 0)
				{
					// if there is no way to colour the connected component of i with numColor colours then goto notFound and increases the numColor
					if (!attempt(i, 1)) goto notFound;
				}
			
/*			for (int i = 0; i < n; i++) 
			{
				cout << (char) ('A' +i) << ":" << colour[i] << endl;
			}
*/			
			cout << numColour << " channel";
			if (numColour > 1) cout << 's';
			cout << " needed." << endl;
			goto anyway;
			
			notFound: {}
		}
		cout << "4 channels needed." << endl;
		anyway: {}
	}
	return 0;
}
